package com.njit.WeStudy.dao;

import com.njit.WeStudy.dataobject.Resource;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

public interface ResourceMapper {
    @Delete({
        "delete from resource",
        "where resource_id = #{resourceId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer resourceId);

    @Insert({
        "insert into resource (resource_name, ",
        "auther_id, is_private, ",
        "create_time, delete_time, ",
        "desc, preview_image_url, ",
        "resource_type)",
        "values (#{resourceName,jdbcType=VARCHAR}, ",
        "#{autherId,jdbcType=INTEGER}, #{isPrivate,jdbcType=BIT}, ",
        "now(), #{deleteTime,jdbcType=TIMESTAMP}, ",
        "#{desc,jdbcType=VARCHAR}, #{previewImageUrl,jdbcType=VARCHAR}, ",
        "#{resourceType,jdbcType=VARCHAR})"
    })
    int insert(Resource record);

    @Select({
        "select",
        "resource_id, resource_name, auther_id, is_private, create_time, delete_time, ",
        "desc, preview_image_url, resource_type",
        "from resource",
        "where resource_id = #{resourceId,jdbcType=INTEGER}"
    })
    @Results(id = "resultMap",value = {
        @Result(column="resource_id", property="resourceId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="resource_name", property="resourceName", jdbcType=JdbcType.VARCHAR),
        @Result(column="auther_id", property="autherId", jdbcType=JdbcType.INTEGER),
        @Result(column="is_private", property="isPrivate", jdbcType=JdbcType.BIT),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="delete_time", property="deleteTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="desc", property="desc", jdbcType=JdbcType.VARCHAR),
        @Result(column="preview_image_url", property="previewImageUrl", jdbcType=JdbcType.VARCHAR),
        @Result(column="resource_type", property="resourceType", jdbcType=JdbcType.VARCHAR)
    })
    Resource selectByPrimaryKey(Integer resourceId);

    @Select({
        "select",
        "resource_id, resource_name, auther_id, is_private, create_time, delete_time, ",
        "desc, preview_image_url, resource_type",
        "from resource"
    })

    @ResultMap("resultMap")
    List<Resource> selectAll();

    @Update({
        "update resource",
        "set resource_name = #{resourceName,jdbcType=VARCHAR},",
          "auther_id = #{autherId,jdbcType=INTEGER},",
          "is_private = #{isPrivate,jdbcType=BIT},",
          "delete_time = #{deleteTime,jdbcType=TIMESTAMP},",
          "desc = #{desc,jdbcType=VARCHAR},",
          "preview_image_url = #{previewImageUrl,jdbcType=VARCHAR},",
          "resource_type = #{resourceType,jdbcType=VARCHAR}",
        "where resource_id = #{resourceId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Resource record);
}